﻿using System;
using Autodesk.Revit.DB;

namespace HYCoordinate
{
	public class TwoInputDataPakcer : InputDataPackerBase
	{
		public Line StartLine
		{
			get
			{
				return this.m_startLine;
			}
			private set
			{
				this.m_startLine = value;
			}
		}

		internal TwoInputDataPakcer(OneInputDataPacker inputStart, OneInputDataPacker inputEnd)
		{
			this.lstInputParameter.Clear();
			this.lstInputParameter.Add(inputStart.GetParameters(0));
			this.lstInputParameter.Add(inputEnd.GetParameters(0));
			this.cornerKind = inputEnd.CornerKinde;
			this.setPoints(inputStart.GetPoint(0), inputEnd.GetPoint(0));
			this.useFamilyFileIndexs.Clear();
			this.useFamilyFileIndexs.Add(inputEnd.GetFamilyFileIndex(0));
		}

		public Line GetLine(int val)
		{
			if (val == 0)
			{
				return this.m_offestLinePostive;
			}
			if (1 == val)
			{
				return this.m_offestLineNegtive;
			}
			return this.m_midLine;
		}

		internal XYZ GetDriection()
		{
			return this.m_driection;
		}

		private void setPoints(XYZ startPoint, XYZ endPoint)
		{
			this.lstPoints.Clear();
			this.lstPoints.Add(startPoint);
			this.lstPoints.Add(endPoint);
			if (startPoint.IsAlmostEqualTo(endPoint))
			{
				throw new CornerMakerException(StaticRescource.StrError_PointsNear);
			}
			this.m_driection = this.lstPoints[1].Add(-this.lstPoints[0]).Normalize();
			this.m_midLine = Line.CreateBound(this.lstPoints[0], this.lstPoints[1]);
			this.m_offestLinePostive = (this.m_midLine.CreateSameOffset(base.GetParameters(1)[UseParameterEnum.Width] / 2.0, StaticRescource.GetXYPlaneNorme(0)) as Line);
			this.m_offestLineNegtive = (this.m_midLine.CreateSameOffset(base.GetParameters(1)[UseParameterEnum.Width] / 2.0, StaticRescource.GetXYPlaneNorme(1)) as Line);
			try
			{
				this.StartLine = Line.CreateBound(this.m_offestLinePostive.GetEndPoint(0), this.m_offestLineNegtive.GetEndPoint(0));
			}
			catch (Exception)
			{
				this.StartLine = null;
			}
		}

		private XYZ m_driection;

		private Line m_midLine;

		private Line m_offestLinePostive;

		private Line m_offestLineNegtive;

		private Line m_startLine;
	}
}
